<template>
  <div class="login">
    <h1>登录</h1>
    <form @submit.prevent="handleLogin">
      <div>
        <label for="username">用户名:</label>
        <input type="text" v-model="username" required />
      </div>
      <div>
        <label for="password">密码:</label>
        <input type="password" v-model="password" required />
      </div>
      <button type="submit">登录</button>
    </form>
    <p v-if="errorMessage" class="error">{{ errorMessage }}</p>
  </div>
</template>

<script>
import { ref } from 'vue'

export default {
  setup() {
    const username = ref('')
    const password = ref('')
    const errorMessage = ref('')

    const handleLogin = () => {
      if (username.value === 'admin' && password.value === '123456') {
        alert('登录成功！')
        // 这里可以添加跳转逻辑
      } else {
        errorMessage.value = '用户名或密码错误'
      }
    }

    return {
      username,
      password,
      errorMessage,
      handleLogin,
    }
  },
}
</script>

<style scoped>
.error {
  color: red;
}
</style>
